﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SerializationTests.cs" company="Marcin Jastrzebski">
//   Copyright (c) Marcin Jastrzebski (marcin@marcinj.net)
// </copyright>
// <summary>
//   The serialization tests.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace TestsRT
{
    using System.Text;

    using KeePassLib.Cryptography;

    using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;

    using mPassRT.Common;
    using mPassRT.ViewModels;

    /// <summary>The serialization tests.</summary>
    [TestClass]
    public class SerializationTests
    {
        #region Public Methods and Operators

        /// <summary>The string serialization.</summary>
        [TestMethod]
        public void StringSerialization()
        {
            var obj = new DatabaseNavigationParameter { FilePath = "Foo", ItemId = "Bar" };

            string str = SerializationUtility.SerializeToString(obj);
            Assert.IsTrue(str.Contains("Database"));
            Assert.IsTrue(str.Contains("Foo"));
            Assert.IsTrue(str.Contains("Group"));
            Assert.IsTrue(str.Contains("Bar"));

            var obj2 = SerializationUtility.DeserializeFromString<DatabaseNavigationParameter>(str);
            Assert.AreEqual(obj.FilePath, obj2.FilePath);
            Assert.AreEqual(obj.ItemId, obj2.ItemId);
        }

        [TestMethod]
        public void QualityEstimationTests()
        {
            uint bits = QualityEstimation.EstimatePasswordBits(Encoding.UTF8.GetBytes("Hiaui087eVxDP5XLZWjg"));
            Assert.AreEqual((uint)111, bits);
            
            bits = QualityEstimation.EstimatePasswordBits(Encoding.UTF8.GetBytes("Password"));
            Assert.AreEqual((uint)6, bits);

            bits = QualityEstimation.EstimatePasswordBits(Encoding.UTF8.GetBytes("12345"));
            Assert.AreEqual((uint)2, bits);
        }

        #endregion
    }
}